﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;

namespace LuDo.PitEditor
{
    public partial class Mailer : Form
    {
        public Mailer(string Subject, string Body)
        {
            InitializeComponent();
            txtSubject.Text = String.Format("[articoli] {0}", Subject); ;
            txtBody.Text = Body;
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage message = new MailMessage();
                message.Subject = txtSubject.Text;
                message.Body = txtBody.Text;
                message.BodyEncoding = Encoding.Default;
                message.From = new MailAddress(PitEditor.Properties.Settings.Default.SmtpOrigin,
                    PitEditor.Properties.Settings.Default.SmtpOriginName);
                message.To.Add(new MailAddress(PitEditor.Properties.Settings.Default.SmtpDestination,
                    PitEditor.Properties.Settings.Default.SmtpDestinationName));
                if (PitEditor.Properties.Settings.Default.SmtpCopyToOrigin)
                {
                    message.Bcc.Add(new MailAddress(PitEditor.Properties.Settings.Default.SmtpOrigin));
                }
                System.Net.Mail.SmtpClient Smtp = new SmtpClient();
                Smtp.Host = PitEditor.Properties.Settings.Default.SmtpHost;
                Smtp.Port = PitEditor.Properties.Settings.Default.SmtpPort;
                Smtp.EnableSsl = true;
                Smtp.Credentials = new System.Net.NetworkCredential(PitEditor.Properties.Settings.Default.SmtpUserName, PitEditor.Properties.Settings.Default.SmtpPassword);
                Smtp.Send(message);
            }
            catch
            {
                this.DialogResult = DialogResult.Cancel;
            }
        }              
    }
}
